function favVocListView (e) {
	var $tr = $(this).parents("tr");
	var $table = $tr.parents('table');
	var vocListId = $(".voc-list-col-0", $tr).text();
	$table.addClass ('fav-voc-table-disabled');
	$tr.after ("<tr><td class='fav-voc-view-expanded-actions' colspan='3'>" +
		"<button class='close'>Close</button></td></tr>");
	// Name field
	var $nameTd = $(".voc-list-col-1", $tr); 
	var name = $nameTd.text();
	// Convert from-to language to select boxes
	var $langTd = $(".voc-list-col-2", $tr);
	var langText = $langTd.text();
	var minIdx = langText.indexOf ("-");
	var fromLang = langText.substr(0, minIdx).trim();
	var toLang = langText.substr(minIdx+1).trim();
	// Convert tags in to edit field
	var $tagsTd = $(".voc-list-col-3", $tr); 
	var tags = $tagsTd.text();
	$table.addClass ("table-view");
	$tr.addClass ("row-view");
	// Words
	var words = "Please wait loading...";
	$tr.after ("<tr><td class='fav-voc-view-expanded' colspan='3'>"+
			"<table><tr><td>Name:</td><td><span class='input-text'>" + name + "</span></td></tr>"+
			"<tr><td>From:</td><td><span class='input-text'>" + fromLang + "</span></td></tr>" +
			"<tr><td>To:</td><td><span class='input-text'>" + toLang + "</span></td></tr>" +
			"<tr><td>Tags:</td><td><span class='input-text'>" + tags + " </span></td></tr>" +
			"<tr><td>Words:</td><td><span class='input-text view-words'" + words + " </span></td></tr></table></td></tr>");
	var $editForm = $(".fav-voc-view-expanded", $table);
	$.get("/learnlang/vocabularyPage/vocList/" + vocListId,
		function(data) {
			$(".view-words", $editForm).text(data.wordsList);
	});
	$(".close").click (function() {
		var $this_tr = $(this).parents("tr");
		var table = $this_tr.parents('table');
		var $prevTr = $this_tr.prev();
		table.removeClass ('fav-voc-table-disabled');
		$this_tr.remove ();
		$prevTr.remove();
		$table.removeClass ("table-view");
		$tr.removeClass ("row-view");
	});
} // favVocListView

function favVocListRemove (e) {
	var name = $(".voc-list-col-1", $(this).parents("tr")).text();
	if (confirm ("Remove vocabulary list <" + name + "> from your favorites?")) {
		$(this).parents('form').submit();
	} // if
} // favVocListRemove 

function submitFavVocListSearch () {
	if ($(".fav-voc-pagination").length) {
		document.forms.searchFavList.action += '?pageSize=10';
		document.forms.searchFavList.action += '&pageIdx=' + $(".fav-voc-pagination").jqPagination('option','current_page');
	} // if
	document.forms.searchFavList.submit();
} // submitFavVocListSearch

$(document).ready(function() {
	$('.fav-voc-view').click (favVocListView);
	$('.fav-voc-remove').click (favVocListRemove);
});

